﻿<!DOCTYPE HTML>
<html  xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head th:include="_meta :: header">
<meta charset="utf-8">
<title>管理员列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 权限配置 <span class="c-gray en">&gt;</span>用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
<form action="#" th:action="@{/user}"  method="post">
	<div class="text-c">
		<input type="text" class="input-text" style="width:250px" placeholder="输入管理员名称" id="" th:value="${name}" name="name"/>
		<button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a sec:authorize="hasAuthority('/user/delete-user')"  href="javascript:;" th:onclick="'javascript:deleteAll(\''+@{/user/deleteAll-user}+'\')'"  class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
			<a sec:authorize="hasAuthority('/user/add-user')" href="javascript:;" onclick="admin_add('添加管理员','/user/add-user',800,500)" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加管理员</a>
		</span>
	<span class="r">共有数据：<strong th:text="${pageInfo.total}"></strong> 条</span> 
	</div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="10">管理员列表</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""/></th>
				<th width="40">ID</th>
				<th width="150">管理员</th>
				<th width="40">性别</th>
				<th width="150">手机</th>
				<th width="180">邮箱</th>
				<th>角色</th>
				<th width="130">加入时间</th>
				<th width="100">是否已启用</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
			<tr class="text-c" th:if="${pageInfo.list.size() == 0}"><td colspan="15"><strong>暂无数据</strong></td></tr>
			<tr class="text-c" th:each="user:${pageInfo.list}">
				<td><input type="checkbox" value="1" th:value="${user.id}" name="id"/></td>
				<td th:text="${user.id}"></td>
				<td th:text="${user.username}"></td>
				<td th:text="${user.sexType ==  1} ? '男' : '女'"></td>
				<td th:text="${user.tel}"></td>
				<td th:text="${user.email}"></td>
				<td >
					<span th:each="role:${user.roles}" th:text="${role.name}"></span>
				</td>
				<td th:text="${#calendars.format(user.createtime,'yyyy-MM-dd')}"></td>
				<td class="td-status" th:if="${user.available}"><span class="label label-success radius" >已启用</span></td>
				<td class="td-status" th:unless="${user.available}"><span class="label radius">已停用</span></td>
				<td class="td-manage">
				
					<a title="停用" sec:authorize="hasAuthority('/user/available-user')"  style="text-decoration:none" th:if="${user.available and user.id != 1}" th:onclick="'javascript:admin_stop(this,\'user'+@{/available-user}+'/'+${user.id}+'\')'" href="javascript:;"><i class="Hui-iconfont">&#xe631;</i></a>
					<a title="启用" th:if="${!user.available and user.id != 1}" sec:authorize="hasAuthority('/user/available-user')"  style="text-decoration:none" th:unless="${user.available}" th:onclick="'javascript:admin_start(this,\'user'+@{/available-user}+'/'+${user.id}+'\')'" href="javascript:;"><i class="Hui-iconfont">&#xe615;</i></a>
					
					<a title="修改密码" sec:authorize="hasAuthority('/user/modify-password')"  href="javascript:;" th:onclick="'javascript:admin_edit(\'修改管理员密码\',\'user'+@{/modify-password}+'/'+${user.id}+'\',800,400)'" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe63f;</i></a>
					<a title="编辑信息" sec:authorize="hasAuthority('/user/edit-user')"  href="javascript:;" th:onclick="'javascript:admin_edit(\'编辑管理员信息\',\'user'+@{/edit-user}+'/'+${user.id}+'\',800,400)'" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
					<a title="删除" th:if="${user.id != 1}"    sec:authorize="hasAuthority('/user/delete-user')"  href="javascript:;" th:onclick="'javascript:admin_del(this,\'user'+@{/delete-user}+'/'+${user.id}+'\')'" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
				
				</td>
			</tr>
			
		</tbody>
	</table>
	<div th:include="_pagination :: page"></div>
	</form>
</div>
<!--_footer 作为公共模版分离出去-->
<div th:replace="_footer :: footerjs">
</div>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/My97DatePicker/4.8/WdatePicker.js}" src="lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" th:src="@{/lib/datatables/1.10.0/jquery.dataTables.min.js}" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" th:src="@{/lib/laypage/1.2/laypage.js}" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
/*管理员-增加*/
function admin_add(title,url,w,h){
	layer_show(title,url,w,h);
}

/*管理员-编辑*/
function admin_edit(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-删除*/
function admin_del(obj,url){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: url,
			dataType: 'json',
			success: function(data){
				if(data == 1){
					window.location.reload();
				}else{
					layer.msg('删除失败!',{icon:5,time:1000});
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

/*管理员-停用*/
function admin_stop(obj,url){
	layer.confirm('确认要停用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
			type: 'POST',
			url: url,
			dataType: 'json',
			success: function(data){
				if(data == 1){
					$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,\''+url+'\')" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label radius">已停用</span>');
					$(obj).remove();
					layer.msg('已停用!',{icon: 6,time:1000});
				}else{
					layer.msg('启用失败!',{icon:5,time:1000});
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}

/*管理员-启用*/
function admin_start(obj,url){
	layer.confirm('确认要启用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
			type: 'POST',
			url: url,
			dataType: 'json',
			success: function(data){
				if(data == 1){
					$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,\''+  url  +'\')" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
					$(obj).remove();
					layer.msg('已启用!', {icon: 6,time:1000});
				}else{
					layer.msg('启用失败!',{icon:5,time:1000});
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}

//批量删除
function deleteAll(url){
	var _list = new Array();
	$('input[name="id"]:checked').each(
          function (i) {
          	_list[i] = $(this).val();
          });
	if(_list.length == 0){
		layer.msg("请选择删除的管理员");
		return false;
	}
  layer.confirm('确定要删除选中的全部数据吗？', {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		 $.ajax({  
	   	     url:url,// 跳转到 action  
	   	     data:JSON.stringify(_list),  
	   	     type:'post',  
	   	     cache:false,  
	   	     dataType:'json', 
	   	     contentType:"application/json",  //发送信息至服务器时内容编码类型。    
	   	     success:function(data) {  
	   	         if(data == 1){  
	   	            window.location.reload();  
	   	         }else{  
	   	        	layer.msg('删除失败!',{icon:5,time:1000});
	   	         }  
	   	      },  
	   	      error : function() {  
	   	    	  layer.msg("异常！");  
	   	      }  
	        });
	}, function() {

	});
}
</script>
</body>
</html>